<?php
namespace Mob \ Model;

use Think \ Model;
use Think \ Hook;
/**同步模型
 * Class InfoModel
 */

require_once ('./Application/Mob/Common/function.php');

class SyncModel extends Model {

    protected $appid;
    protected $secrect;


    function  __construct()
    {
        $this->appid = C('Wx_AppID');
        $this->secrect = C('Wx_AppSecret');


    }




   public function wxUserImage($Uid)
   {

    $wxUser = M('wx_user')->where(array('UserId'=>$Uid,'status'=>1))->field('OpenId,headimgurl,UserId')->find();  //取微信用户


   $wxcommon = D('WxCommon');  //实例化微信公用模型
   $wx = D('WxUser');         //实例化微信用户模型
   $access_token = $wxcommon->getToken();

   $userinfo = $wxcommon->get_user_info($access_token,$wxUser['OpenId']);


   if($userinfo)
   {
   	if($userinfo['headimgurl']!=$wxUser['headimgurl'])
   	{
    $wx->updateWxAvatarImg($wxUser['UserId'],$userinfo['headimgurl']);
   $filename= $wx->getWxAvatarImg($wxUser['OpenId']);
    if($filename)
    {
   clean_query_user_cache($Uid, array('avatar256', 'avatar128', 'avatar64', 'avatar32', 'avatar512'));   //执行清理缓存操作
   return true;
    }
   	}
   else
   {
   return true;
   }

   }

   }












  /**
     * 发送get请求
     * @param string $url
     * @return bool|mixed
     */
    function request_get($url = '')
    {
        if (empty($url)) {
            return false;
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }










}